﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Quick.CodeGenerator.Model;

namespace Quick.CodeGenerator.CodeTemplate
{
    public class RepositoriesTemplate : ITemplate
    {
        /// <summary>
        /// 生成模版
        /// </summary>
        /// <param name="setting"></param>
        /// <returns></returns>
        public string GenerateTemplate(CodeGeneratorSetting setting, string tableName, List<Model.ColumnInfo> columns)
        {
            StringBuilder strBuilder = new StringBuilder();
            strBuilder.AppendLine($"/****************");
            strBuilder.AppendLine($"* Creat Date: {DateTime.Now.ToString("yyyy/MM/dd hh:mm:ss")}");
            strBuilder.AppendLine($"* Creator: {setting.Creator}");
            strBuilder.AppendLine($"*****************/");
            strBuilder.AppendLine($"using System;");
            strBuilder.AppendLine($"using System.Data;");
            strBuilder.AppendLine($"using System.Text;");
            strBuilder.AppendLine($"using System.Collections.Generic;");
            strBuilder.AppendLine($"using System.Linq;");
            strBuilder.AppendLine($"using {setting.Project}.{setting.EntityNamespace};");
            strBuilder.AppendLine($"namespace {setting.Project}.{setting.RepositoryNamespace}");
            strBuilder.AppendLine("{");
            strBuilder.AppendLine("    /// <summary>");
            strBuilder.AppendLine("    /// 数据表操作实体类：" + tableName);
            strBuilder.AppendLine("    /// </summary>");
            strBuilder.AppendLine("    [Serializable]");
            strBuilder.AppendLine($"    public partial class {tableName}Repository :QuickFramework.SqlSugarOrm.Repository<{setting.Project}.{setting.EntityNamespace}.{tableName}>, {setting.Project}.{setting.ContractsNamespace}.I{tableName}Repository");
            //strBuilder.AppendLine($"    public partial class {tableName}Repository : QuickFramework.Orm.Repository, {setting.Project}.{setting.ContractsNamespace}.I{tableName}Repository");
            strBuilder.AppendLine("    {");
            strBuilder.AppendLine("        /// <summary>");
            strBuilder.AppendLine("        /// 构造方法,初始化数据库链接：" + tableName);
            strBuilder.AppendLine("        /// </summary>");
            strBuilder.AppendLine($"        public {tableName}Repository() : base({setting.DbConnectionStringName})");
            strBuilder.AppendLine("        { }");
            strBuilder.AppendLine("        /// <summary>");
            strBuilder.AppendLine("        /// 构造方法,初始化数据库链接：" + tableName);
            strBuilder.AppendLine("        /// </summary>");
            strBuilder.AppendLine($"        public {tableName}Repository(string dbConnectionString) : base(dbConnectionString)");
            strBuilder.AppendLine("        { }");
            strBuilder.AppendLine("    }");
            strBuilder.AppendLine("}");
            return strBuilder.ToString();
        }
    }
}